<?php
	session_start();
	require_once("LeaveFormView.php");
	require_once("LeaveFormController.php");
	require_once("functions.php");
	
	if(isset($_SESSION['login']) && $_SESSION['login']==true){
	$totalRows = $_POST['totalRows'];
	$employeeNumber = $_POST['employeeNumber'];
	

	$link = makeSQLconnection();
	$q = sprintf("SELECT * from `EMPLOYEE` where Employee_number = '$employeeNumber'");
	$r = mysql_query($q, $link);
	$data = mysql_fetch_assoc($r);
	$gender = $data['Employee_gender'];
	mysql_close($link);
		for ($i = 0; $i<$totalRows; $i++) {
	
		$dF = "dateOfFiling".$i;
		$dR = "dateReceived".$i;
		$tL = "typeOfLeave".$i;
		$d = "days".$i;		
		$sD = "startDate".$i;
		$eD = "endDate".$i;
		$s = "status".$i;		
		$t = "time".$i;
		$lN = "leaveNum".$i;
		
		$dateOfFiling = $_POST[$dF];
		$_SESSION[$dF] = $_POST[$dF];
		$dateReceived = $_POST[$dR];
		$_SESSION[$dR] = $_POST[$dR];
		$typeOfLeave = $_POST[$tL];
		$_SESSION[$tL] = $_POST[$tL];
		$days = $_POST[$d];		
		$_SESSION[$d] = $_POST[$d];		
		$startDate = $_POST[$sD];
		$_SESSION[$sD] = $_POST[$sD];
		$endDate = $_POST[$eD];
		$_SESSION[$eD] = $_POST[$eD];
		$status = $_POST[$s];		
		$_SESSION[$s] = $_POST[$s];		
		$time = $_POST[$t];
		$_SESSION[$t] = $_POST[$t];
		$leaveNumber = $_POST[$lN];
		$_SESSION[$lN] = $_POST[$lN];
		
		$errorFlag = 0;
		$daysComputed = 1;

		$dFError = 0;
		$dRError = 0;
		$daysError = 0;
		$daysError2 = 0;
		$daysError3 = 0;
		$typeOfError = "";
		$sDError = 0;
		$eDError = 0;
		$eDError2 = 0;
		$sError = 0;
				
		
		//ibig sabihin may nilagay siya sa date of filing
		if ($dateOfFiling) {
			$result1 = checkFormat($dateOfFiling);
			$dFyear = substr($dateOfFiling, 6,10);
			$dFmonth = substr($dateOfFiling, 0, 2);
			$dFday = substr($dateOfFiling, 3,-5);	

			if	($result1) {		
				$result = validateDate ($dFmonth, $dFday, $dFyear);		
				
				if	(!$result) {
					
					$dFError = true;
					$errorFlag = 1;			
				}
				
			} else {
				$errorFlag = 1;
				$dFError = true;					
			}						
		}
		
		if ($dateReceived) {
			$result1 = checkFormat($dateReceived);
			$dRyear = substr($dateReceived, 6,10);
			$dRmonth = substr($dateReceived, 0, 2);
			$dRday = substr($dateReceived, 3,-5);	

			if	($result1) {		
				$result = validateDate ($dRmonth, $dRday, $dRyear);		
				
				if	(!$result) {
					
					$dRError = true;
					$errorFlag = 1;			
				}
				
			} else {
				$errorFlag = 1;
				$dRError = true;					
			}
		}
		
		$dRError2 = false;
		if ($dateReceived && $dateOfFiling) {
			if ($dFyear > $dRyear) {
				//02 29 2009 && 02 06 2008
				$errorFlag = 1;
				$dRError2 = true;				
			} else if ($dFyear == $dRyear) {
				//02 01 2009 && 02 06 2009					
				if ($dFmonth > $dRmonth) {
					//02 02 2008 && 01 06 2008
					$errorFlag = 1;
					$dRError2 = true;
				} else if ($dFmonth == $dRmonth) {
					//02 21 2008 && 02 06 2008	
					if ($dFday > $dRday) {
						$errorFlag = 1;
						$dRError2 = true;
					}
				}
			}
		}
		
		//validate days
		if (strlen($days) == 0) {
			
			$errorFlag = 1;
			$daysError = 1;
		}
			
		$result1 = checkFormat($startDate);
		
		if	($result1) {

			$startYear = substr($startDate, 6,10);
			$startMonth = substr($startDate, 0, 2);
			$startDay = substr($startDate, 3,-5);

	
			$result = validateDate ($startMonth, $startDay, $startYear);		
			if	(!$result) {
				
				$sDError = 1;
				$errorFlag = 1;
			}
		
		} else {
			
			$errorFlag = 1;
			$sDError = 1;	
			
		}
		
		$result1 = checkFormat($endDate);
		
		if	($result1) {		
			
			$endYear = substr($endDate, 6,10);
			$endMonth = substr($endDate, 0, 2);
			$endDay = substr($endDate, 3,-5);		
			
			$result = validateDate ($endMonth, $endDay, $endYear);		
			
			if	(!$result) {
				
				$eDError = 1;
				$errorFlag = 1;			
			}
			
		} else {
			$errorFlag = 1;
			$eDError = 1;					
		}
		
		if (!$sDError && !$eDError) {
			//checks validity of end date
			if ( $endYear < $startYear ) {
				//nauna ung end year sa start year
				$errorFlag = 1;
				$eDError2 = 1;
			} else if ($endYear==$startYear){
				//tama ung year, BUT...
				if ( $endMonth < $startMonth ) {
					//nauna ung end month sa start month			
					$errorFlag = 1;	
					$eDError2 = 1;
				} else if ( $endMonth ==  $startMonth ) {
					//same month 
					if ($endDay < $startDay) {
						//nauna ung end day sa start day				
						$errorFlag = 1;				
						$eDError2 = 1;
					} 
				} 
			} 
		}
		
		if($status == "null"){
			$errorFlag = 1;
			$sError = 1;
		}		
		
		//computation of days between start date and end date
		
		$link = makeSQLconnection();
		
		if ($typeOfLeave != "UNDERTIME" && $typeOfLeave != 'TARDINESS') {
			
			if (!$sDError && !$eDError && !$eDError2) {
			
				$nextDate = $startYear."-".$startMonth."-".$startDay;
				$tempDate = $endYear."-".$endMonth."-".$endDay;
				
				if($nextDate != $tempDate){
					while(1) {
											
						$query = "SELECT INTERVAL 1 DAY + '".$nextDate."' AS nextDate";
						
						$r2 = mysql_query($query, $link);
						$data1 = mysql_fetch_assoc($r2);
						
						$nextDateYear = substr($data1['nextDate'], 0, -6);
						$nextDateMonth = substr($data1['nextDate'], 5, -3);
						$nextDateDay = substr($data1['nextDate'], 8, 10);
						$nextDate = $nextDateYear."-".$nextDateMonth."-".$nextDateDay;
												
						$query = "SELECT DAYNAME('".$nextDateYear."-".$nextDateMonth."-".$nextDateDay."') AS dayOfWeek";
						$r1 = mysql_query($query, $link);					
						$data = mysql_fetch_assoc($r1);
							
						if ($data['dayOfWeek'] != "Saturday" && $data['dayOfWeek'] != "Sunday") {			
							
							++$daysComputed;
						}
					
						if ($endDay == $nextDateDay && $endMonth  == $nextDateMonth && $endYear == $nextDateYear)
							break;
					}
				}
				
				if ($daysComputed != $days) {
						$daysError2 = 1;
						$errorFlag = 1;
				}
			}	
		
		} else {
			if ($days >= 1) {			
					$daysError = 1;
					$errorFlag = 1;
			}
		}
		
		if ($typeOfLeave == "SPECIAL") {
				
				$query = "SELECT * FROM `leaveform` WHERE `Type_of_leave` = '$typeOfLeave' and `Employee_number` = '$employeeNumber'";						
				$r2 = mysql_query($query, $link);
				$specialDays = 0;
								
				while($data1 = mysql_fetch_assoc($r2)) {
					$specialDays += $data1['Days'];					
				}
				
				if ($specialDays > 6) {
					$daysError3 = 1;
					$errorFlag = 1;
					$typeOfError = "special";
				}
				
			} else if ($typeOfLeave == "PATERNITY") {
				
				$query = "SELECT * FROM `leaveform` WHERE `Type_of_leave` = '$typeOfLeave' and `Employee_number` = '$employeeNumber'";						
				$r2 = mysql_query($query, $link);
				$paternityDays = 0;
								
				while($data1 = mysql_fetch_assoc($r2)) {
					$paternityDays += $data1['Days'];					
				}
				
				if ($paternityDays > 7) {
					$daysError3 = 1;
					$errorFlag = 1;
					$typeOfError = "Paternal Leave";
				}
			} else if ($typeOfLeave == "REHABILITATION") {
				
				$query = "SELECT * FROM `leaveform` WHERE `Type_of_leave` = '$typeOfLeave' and `Employee_number` = '$employeeNumber'";						
				$r2 = mysql_query($query, $link);
				$rehabDays = 0;
								
				while($data1 = mysql_fetch_assoc($r2)) {
					$rehabDays += $data1['Days'];					
				}
				
				if ($rehabDays > 120) {
					$daysError3 = 1;
					$errorFlag = 1;
					$typeOfError = "Rehabilitation Leave";
				}
			}  else if ($typeOfLeave == "FORCED") {
				
				$query = "SELECT * FROM `leaveform` WHERE `Type_of_leave` = '$typeOfLeave' and `Employee_number` = '$employeeNumber'";						
				$r2 = mysql_query($query, $link);
				$forcedDays = 0;
								
				while($data1 = mysql_fetch_assoc($r2)) {
					$forcedDays += $data1['Days'];					
				}
				
				if ($forcedDays > 5) {
					$daysError3 = 1;
					$errorFlag = 1;
					$typeOfError = "Forced Leave";
				}
			}
		
		
		
		/*
		* row where errors are displayed
		*  it is made when an error occurs
		*/
		
		if (!$errorFlag) {
			$_SESSION['valid'] = true;
			LeaveFormView :: requestEditLeave($employeeNumber);
		}		
	}
?>
	<html>
		<head>
			<link href="template.css" rel="stylesheet" type="text/css" media="screen" />
			<title>Edit Leave Form</title>
			<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js' type='text/javascript'></script>
			<script src='jquery.js'></script>
			<script language='javascript'>
				function undertimeIsSelected(ctr)
				{
					var typeOfLeave = "typeOfLeave"+ctr;
					if (document.getElementById(typeOfLeave).value == 'UNDERTIME'  || document.getElementById(typeOfLeave).value == 'TARDINESS') {
						do{
							var x = prompt('Input Hours', 'hours');
						}while(isNaN(x));
						if(x != null){
							do{
								var y = prompt('Input Minutes', 'minutes');
							}while(isNaN(y));
							if(y != null){
								var days = (parseInt(60*x) + parseInt(y))/1440;
								if(isNaN(days)) document.getElementById('days').value = '';
								else {
									var days2 = 'days'+ctr;
									var time = 'time'+ctr;
									document.getElementById(days2).value = days;
									var d = parseInt(x) + '/' + parseInt(y);
									document.getElementById(time).value=d;
									
								}
							}
						}
					} else { 
						var time = 'time'+ctr;
						document.getElementById(time).value=''; 
					}
				}
			</script>
			<script>
				var timeout = 500;
				var closetimer = 0;
				var ddmenuitem = 0;

				function jsddm_open()
				{  jsddm_canceltimer();
				   jsddm_close();
				   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

				function jsddm_close()
				{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

				function jsddm_timer()
				{  closetimer = window.setTimeout(jsddm_close, timeout);}

				function jsddm_canceltimer()
				{  if(closetimer)
				   {  window.clearTimeout(closetimer);
					  closetimer = null;}}

				$(document).ready(function()
				{  $('#jsddm > li').bind('mouseover', jsddm_open)
				   $('#jsddm > li').bind('mouseout',  jsddm_timer)});

				document.onclick = jsddm_close;			
				
				$(document).ready(function(){
							   
		   $("a").css({
			'text-decoration':'none',
		   });
		   $("a").hover(function () {
				$(this).css({'text-decoration':'none','font-weight':'bold'});
			  }, function () {
				var cssObj = {
				  'text-decoration':'none',
				  'font-weight':''
				}
				$(this).css(cssObj);
			  });
									   
		   $("#submit").css({
				'background-color':'white',
				'color':'#2F2825'
			});
			$("#submit").hover(function () {
				$(this).css({'background-color' : '#993333','color':'white','font-weight':'bold'});
			  }, function () {
				var cssObj = {
				  'background-color' : 'white',
				  'color' : '#2F2825',
				  'font-weight':''
				}
				$(this).css(cssObj);
			  });				  
				 
		 });
			</script>
			</head>
		<body>
			<!-- start header -->
			<div id="header">
				<div id="logo">
					<h1><span>UPLB</span> &nbsp; Leave Application</h1><br/>
					<ul id="jsddm">
						<?php if(isset($_SESSION['login']) && $_SESSION['login']==true) {?>
						<li><a href="#">ACTIONS <span>&#x25BC</span></a>
							<ul>
								<li><a href="AddEmployee.php">Add Employee</a></li>
								<li><a href="searchEmployee.php">Change Employee</a></li>
							</ul>
						</li>
						<li><a href="logout.php">LOG OUT</a>
						</li>
						<?php } ?>
					</ul>
				</div>
			</div>
			<!-- end header -->
			<div id="wrapper">
				<!-- start page -->
				<div id="pageEdit">
				<div id="page-bgEdit">					
					<!-- start content -->
				<div class='leaveData'>	
				<?php LeaveFormView :: getEmployeeData($employeeNumber); ?>					
					<div id="content">
						<div class="post">							
								<form name='editLeave' method='post' action='validateEdit.php'>
									<center>
									<table>			
										<tr>
											<td>Leave Number&nbsp;&nbsp;<br /><font size='1'>&nbsp;&nbsp;</font></td>
											<td>Date of Filing<br/><font size='1'>(mm/dd/yyyy)</font></td>
											<td>Date Received<br/><font size='1'>(mm/dd/yyyy)</font></td>
											<td>Type of Leave<br /><font size='1'>&nbsp;&nbsp;</font></td>
											<td>Days<br /><font size='1'>&nbsp;&nbsp;</font></td>
											<td>Start Date<br/><font size='1'>(mm/dd/yyyy)</font></td>
											<td>End Date<br/><font size='1'>(mm/dd/yyyy)</font></td>
											<td>Status<br /><font size='1'>&nbsp;&nbsp;</font></td>
										</tr>
		<?php				
		for ($i = 0; $i<$totalRows; $i++) {
	
		$dF = "dateOfFiling".$i;
		$dR = "dateReceived".$i;
		$tL = "typeOfLeave".$i;
		$d = "days".$i;		
		$sD = "startDate".$i;
		$eD = "endDate".$i;
		$s = "status".$i;		
		$t = "time".$i;
		$lN = "leaveNum".$i;
		
		$dateOfFiling = $_POST[$dF];
		$_SESSION[$dF] = $_POST[$dF];
		$dateReceived = $_POST[$dR];
		$_SESSION[$dR] = $_POST[$dR];
		$typeOfLeave = $_POST[$tL];
		$_SESSION[$tL] = $_POST[$tL];
		$days = $_POST[$d];		
		$_SESSION[$d] = $_POST[$d];		
		$startDate = $_POST[$sD];
		$_SESSION[$sD] = $_POST[$sD];
		$endDate = $_POST[$eD];
		$_SESSION[$eD] = $_POST[$eD];
		$status = $_POST[$s];		
		$_SESSION[$s] = $_POST[$s];		
		$time = $_POST[$t];
		$_SESSION[$t] = $_POST[$t];
		$leaveNumber = $_POST[$lN];
		$_SESSION[$lN] = $_POST[$lN];
		
		$errorFlag = 0;
		$daysComputed = 1;

		$dFError = 0;
		$dRError = 0;
		$daysError = 0;
		$daysError2 = 0;
		$daysError3 = 0;
		$typeOfError = "";
		$sDError = 0;
		$eDError = 0;
		$eDError2 = 0;
		$sError = 0;
				
		
		//ibig sabihin may nilagay siya sa date of filing
		if ($dateOfFiling) {
			$result1 = checkFormat($dateOfFiling);
			$dFyear = substr($dateOfFiling, 6,10);
			$dFmonth = substr($dateOfFiling, 0, 2);
			$dFday = substr($dateOfFiling, 3,-5);	

			if	($result1) {		
				$result = validateDate ($dFmonth, $dFday, $dFyear);		
				
				if	(!$result) {
					
					$dFError = true;
					$errorFlag = 1;			
				}
				
			} else {
				$errorFlag = 1;
				$dFError = true;					
			}						
		}
		
		if ($dateReceived) {
			$result1 = checkFormat($dateReceived);
			$dRyear = substr($dateReceived, 6,10);
			$dRmonth = substr($dateReceived, 0, 2);
			$dRday = substr($dateReceived, 3,-5);	

			if	($result1) {		
				$result = validateDate ($dRmonth, $dRday, $dRyear);		
				
				if	(!$result) {
					
					$dRError = true;
					$errorFlag = 1;			
				}
				
			} else {
				$errorFlag = 1;
				$dRError = true;					
			}
		}
		
		$dRError2 = false;
		if ($dateReceived && $dateOfFiling) {
			if ($dFyear > $dRyear) {
				//02 29 2009 && 02 06 2008
				$errorFlag = 1;
				$dRError2 = true;				
			} else if ($dFyear == $dRyear) {
				//02 01 2009 && 02 06 2009					
				if ($dFmonth > $dRmonth) {
					//02 02 2008 && 01 06 2008
					$errorFlag = 1;
					$dRError2 = true;
				} else if ($dFmonth == $dRmonth) {
					//02 21 2008 && 02 06 2008	
					if ($dFday > $dRday) {
						$errorFlag = 1;
						$dRError2 = true;
					}
				}
			}
		}
		
		//validate days
		if (strlen($days) == 0) {
			
			$errorFlag = 1;
			$daysError = 1;
		}
			
		$result1 = checkFormat($startDate);
		
		if	($result1) {

			$startYear = substr($startDate, 6,10);
			$startMonth = substr($startDate, 0, 2);
			$startDay = substr($startDate, 3,-5);

	
			$result = validateDate ($startMonth, $startDay, $startYear);		
			if	(!$result) {
				
				$sDError = 1;
				$errorFlag = 1;
			}
		
		} else {
			
			$errorFlag = 1;
			$sDError = 1;	
			
		}
		
		$result1 = checkFormat($endDate);
		
		if	($result1) {		
			
			$endYear = substr($endDate, 6,10);
			$endMonth = substr($endDate, 0, 2);
			$endDay = substr($endDate, 3,-5);		
			
			$result = validateDate ($endMonth, $endDay, $endYear);		
			
			if	(!$result) {
				
				$eDError = 1;
				$errorFlag = 1;			
			}
			
		} else {
			$errorFlag = 1;
			$eDError = 1;					
		}
		
		if (!$sDError && !$eDError) {
			//checks validity of end date
			if ( $endYear < $startYear ) {
				//nauna ung end year sa start year
				$errorFlag = 1;
				$eDError2 = 1;
			} else if ($endYear==$startYear){
				//tama ung year, BUT...
				if ( $endMonth < $startMonth ) {
					//nauna ung end month sa start month			
					$errorFlag = 1;	
					$eDError2 = 1;
				} else if ( $endMonth ==  $startMonth ) {
					//same month 
					if ($endDay < $startDay) {
						//nauna ung end day sa start day				
						$errorFlag = 1;				
						$eDError2 = 1;
					} 
				} 
			} 
		}
		
		if($status == "null"){
			$errorFlag = 1;
			$sError = 1;
		}		
		
		//computation of days between start date and end date
		
		$link = makeSQLconnection();
		
		if ($typeOfLeave != "UNDERTIME" && $typeOfLeave != 'TARDINESS') {
			
			if (!$sDError && !$eDError && !$eDError2) {
			
				$nextDate = $startYear."-".$startMonth."-".$startDay;
				$tempDate = $endYear."-".$endMonth."-".$endDay;
				
				if($nextDate != $tempDate){
					while(1) {
											
						$query = "SELECT INTERVAL 1 DAY + '".$nextDate."' AS nextDate";
						
						$r2 = mysql_query($query, $link);
						$data1 = mysql_fetch_assoc($r2);
						
						$nextDateYear = substr($data1['nextDate'], 0, -6);
						$nextDateMonth = substr($data1['nextDate'], 5, -3);
						$nextDateDay = substr($data1['nextDate'], 8, 10);
						$nextDate = $nextDateYear."-".$nextDateMonth."-".$nextDateDay;
												
						$query = "SELECT DAYNAME('".$nextDateYear."-".$nextDateMonth."-".$nextDateDay."') AS dayOfWeek";
						$r1 = mysql_query($query, $link);					
						$data = mysql_fetch_assoc($r1);
							
						if ($data['dayOfWeek'] != "Saturday" && $data['dayOfWeek'] != "Sunday") {			
							
							++$daysComputed;
						}
					
						if ($endDay == $nextDateDay && $endMonth  == $nextDateMonth && $endYear == $nextDateYear)
							break;
					}
				}
				
				if ($daysComputed != $days) {
						$daysError2 = 1;
						$errorFlag = 1;
				}
			}	
		
		} else {
			if ($days >= 1) {			
					$daysError = 1;
					$errorFlag = 1;
			}
		}
		
		if ($typeOfLeave == "SPECIAL") {
				
				$query = "SELECT * FROM `leaveform` WHERE `Type_of_leave` = '$typeOfLeave' and `Employee_number` = '$employeeNumber'";						
				$r2 = mysql_query($query, $link);
				$specialDays = 0;
								
				while($data1 = mysql_fetch_assoc($r2)) {
					$specialDays += $data1['Days'];					
				}
				
				if ($specialDays > 6) {
					$daysError3 = 1;
					$errorFlag = 1;
					$typeOfError = "special";
				}
				
			} else if ($typeOfLeave == "PATERNITY") {
				
				$query = "SELECT * FROM `leaveform` WHERE `Type_of_leave` = '$typeOfLeave' and `Employee_number` = '$employeeNumber'";						
				$r2 = mysql_query($query, $link);
				$paternityDays = 0;
								
				while($data1 = mysql_fetch_assoc($r2)) {
					$paternityDays += $data1['Days'];					
				}
				
				if ($paternityDays > 7) {
					$daysError3 = 1;
					$errorFlag = 1;
					$typeOfError = "Paternal Leave";
				}
			} else if ($typeOfLeave == "REHABILITATION") {
				
				$query = "SELECT * FROM `leaveform` WHERE `Type_of_leave` = '$typeOfLeave' and `Employee_number` = '$employeeNumber'";						
				$r2 = mysql_query($query, $link);
				$rehabDays = 0;
								
				while($data1 = mysql_fetch_assoc($r2)) {
					$rehabDays += $data1['Days'];					
				}
				
				if ($rehabDays > 120) {
					$daysError3 = 1;
					$errorFlag = 1;
					$typeOfError = "Rehabilitation Leave";
				}
			}  else if ($typeOfLeave == "FORCED") {
				
				$query = "SELECT * FROM `leaveform` WHERE `Type_of_leave` = '$typeOfLeave' and `Employee_number` = '$employeeNumber'";						
				$r2 = mysql_query($query, $link);
				$forcedDays = 0;
								
				while($data1 = mysql_fetch_assoc($r2)) {
					$forcedDays += $data1['Days'];					
				}
				
				if ($forcedDays > 5) {
					$daysError3 = 1;
					$errorFlag = 1;
					$typeOfError = "Forced Leave";
				}
			}
		
		
		
		/*
		* row where errors are displayed
		*  it is made when an error occurs
		*/		
		
		if ($errorFlag)  {
		
			echo "<tr>";
			
			echo"<td>&nbsp;</td>";
			
			if ($dFError) {
				echo "<td><span class='error'>Incorrect date of filing.</font></td>";	
			} else {
				echo "<td>&nbsp;</td>";
			}
			
			if ($dRError) {									
				echo "<td><span class='error'>Incorrect date received.</font></td>";	
				
			} else {		
				if ($dRError2) {
					echo "<td><span class='error'>Date received is earlier<br />than date of filing.</font></td>";	
				} else {
					echo "<td>&nbsp;</td>";
				}
			}
			
			//for type of leave. there'll be no errors?
			echo"<td>&nbsp;</td>";			
			
			if ($daysError) {
				echo "<td><span class='error'>Days empty.</span></td>";
			} else {
				//print nothing sa error ROW
				if ($daysError2) {
					echo "<td><span class='error'>Incorrect days.</span></td>";
				}else {
					if ($daysError3) {
						echo "<td><span class='error'>".$typeOfError." days exceeded.</span></td>";
					} else {
						echo "<td>&nbsp;</td>";
					}
				}
			}
			
			if ($sDError) {
				echo "<td><span class='error'>Incorrect start date.</span></td>";												
			}
			else {							
				//print nothing sa error ROW
				echo "<td>&nbsp;</td>";
			}
			
			if ($eDError) {
				echo "<td><span class='error'>Incorrect end date.</span></td>";
			} else {
				if ($eDError2) {
					echo "<td><span class='error'>End date is earlier<br />than start date.</span></td>";
				} else {						
					//print nothing sa error ROW
					echo "<td>&nbsp;</td>";
				}
			}

			if ($sError) {
				echo "<td><span class='error'>No type of status selected.</span></td>";
			} else {
				echo "<td>&nbsp;</td>";
			}								
			
			echo "</tr>";
		
			/*
			* end of the error row
			*/
		
		}

		echo "<tr>";		
		
		echo "<td>".$leaveNumber."</td>";
		
		echo "<td><input type='text' name='dateOfFiling".$i."' id='dateOfFiling".$i."' value='".$dateOfFiling."' size='6' maxlength=10></td>			
			<td><input type='text' name='dateReceived".$i."' id='dateReceived".$i."' value='".$dateReceived."' size='6' maxlength=10></td>";	
		
		/*
		* type of leave cell
		*/
		
		echo "<td><select name='typeOfLeave".$i."' id='typeOfLeave".$i."' onChange='undertimeIsSelected(".$i.")'>";
		
				if($typeOfLeave == "SICK_LEAVE") {
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE' selected='1'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL' >Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'  >Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'  >Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL'  >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION'  >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'  >Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'  >Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION'  >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					if($gender=='Female'){
						echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
					}else{
						echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
					}
				} else if ($typeOfLeave == "VACATION_LEAVE") {
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE' selected='1'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL' >Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'  >Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'  >Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL'  >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION'  >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'  >Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'  >Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION'  >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					if($gender=='Female'){
						echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
					}else{
						echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
					}
				} else if ($typeOfLeave == "AWOL") {
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL' selected='1'>Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'  >Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'  >Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL'  >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION'  >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'  >Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'  >Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION'  >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					if($gender=='Female'){
						echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
					}else{
						echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
					}
				} else if ($typeOfLeave == "COMPENSATORY") {
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL'>Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY' selected='1'>Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'  >Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL'  >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION'  >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'  >Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'  >Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION'  >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					if($gender=='Female'){
						echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
					}else{
						echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
					}
				} else if ($typeOfLeave == "FORCED") {
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL'>Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'>Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED' selected='1'>Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL'  >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION'  >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'  >Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'  >Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION'  >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					if($gender=='Female'){
						echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
					}else{
						echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
					}
				} else if ($typeOfLeave == "MONET_SL") {
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL'>Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'>Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'>Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL' selected='1'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL'  >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION'  >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'  >Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'  >Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION'  >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					if($gender=='Female'){
						echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
					}else{
						echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
					}
				} else if ($typeOfLeave == "MONET_VL") {
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL'>Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'>Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'>Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL' selected='1'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL'  >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION'  >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'  >Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'  >Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION'  >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					if($gender=='Female'){
						echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
					}else{
						echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
					}
				} else if ($typeOfLeave == "PARENTAL") {
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL'>Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'>Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'>Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL' selected='1'  >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION'  >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'  >Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'  >Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION'  >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					if($gender=='Female'){
						echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
					}else{
						echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
					}
				} else if ($typeOfLeave == "REHABILITATION") {
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL'>Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'>Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'>Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL' >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION' selected='1'   >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'  >Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'  >Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION'  >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					if($gender=='Female'){
						echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
					}else{
						echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
					}
				}  else if ($typeOfLeave == "RE-ENERGIZING") {
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL'>Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'>Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'>Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL' >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION' >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING' selected='1'  >Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'  >Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION'  >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					if($gender=='Female'){
						echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
					}else{
						echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
					}
				}  else if ($typeOfLeave == "SPECIAL") {
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option n\ame='AWOL' value='AWOL'>Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'>Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'>Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL' >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION' >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'>Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL' selected='1' >Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION'  >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					if($gender=='Female'){
						echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
					}else{
						echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
					}
				}  else if ($typeOfLeave == "SUSPENSION") {
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL'>Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'>Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'>Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL' >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION' >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'>Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'>Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION' selected='1' >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					if($gender=='Female'){
						echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
					}else{
						echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
					}
				}  else if ($typeOfLeave == "TARDINESS") {
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL'>Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'>Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'>Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL' >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION' >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'>Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'>Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION' >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS' selected='1'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					if($gender=='Female'){
						echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
					}else{
						echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
					}
				}  else if ($typeOfLeave == "UNDERTIME") {
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL'>Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'>Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'>Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL' >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION' >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'>Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'>Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION' >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME' selected='1'>Undertime</option>";
					if($gender=='Female'){
						echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
					}else{
						echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
					}
				}  else if ($typeOfLeave == "MATERNAL") {
					echo "<option name='null' value='null'>[Select Type]</option>";							
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL'>Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'>Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'>Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL' >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION' >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'>Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'>Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION' >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					echo "<option name='MATERNAL' value='MATERNAL' selected='true'>Maternal</option>";
				}  else if ($typeOfLeave == "PATERNAL") {
					echo "<option name='null' value='null'>[Select Type]</option>";							
					echo "<option name='SICK_LEAVE' value='SICK_LEAVE'>Sick Leave</option>";							
					echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'>Vacation Leave&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";							
					echo "<option name='AWOL' value='AWOL'>Absence Without Leave</option>";		
					echo "<option name='COMPENSATORY' value='COMPENSATORY'>Compensatory</option>";											
					echo "<option name='FORCED' value='FORCED'>Forced Leave</option>";
					echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";
					echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";
					echo "<option name='PARENTAL' value='PARENTAL' >Parental Leave</option>";
					echo "<option name='REHABILITATION' value='REHABILITATION' >Rehabilitation</option>";
					echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'>Re-energizing</option>";
					echo "<option name='SPECIAL' value='SPECIAL'>Special Leave</option>";
					echo "<option name='SUSPENSION' value='SUSPENSION' >Suspension</option>";
					echo "<option name='TARDINESS' value='TARDINESS'>Tardiness</option>";
					echo "<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
					echo "<option name='PATERNAL' value='PATERNAL' selected='true'>Paternal</option>";
				}  

		echo "</select></td>";
		
		//end of cell
	
		/*
		* days, start date, end date cells
		*/
	
		echo "<td>
				<input type='text' name='days".$i."' id='days".$i."' size='2' maxlength='2' value='".$days."'/>
			</td>
			<td>
				<input type='text' name='startDate".$i."' id='startDate".$i."' size='6' maxlength='10' value='".$startDate."'/>
			</td>
			<td>
				<input type='text' name='endDate".$i."' id='endDate".$i."' size='6' maxlength='10' value='".$endDate."'/>
			</td>";
		
		//end of cell
		
		/*
		* status cell
		*/
		
		echo "<td><select name='status".$i."' id='status".$i."'>";
		if ($status == "WITH_PAY") {
			echo "<option name='WITH_PAY' value='WITH_PAY' selected='1'>Approved With Pay</option>";
		} else {
			echo "<option name='WITH_PAY' value='WITH_PAY'>Approved With Pay</option>";
		}
		if ($status == "WITHOUT_PAY") {
			echo "<option name='WITHOUT_PAY' value='WITHOUT_PAY' selected='1'>Approved Without Pay</option>";
		} else {
			echo "<option name='WITHOUT_PAY' value='WITHOUT_PAY'>Approved Without Pay</option>";
		}								
		echo "</select></td>";
		
		//end of cell
		
		echo "</tr>";
		echo "<tr><td><input type='hidden' name='employeeNumber' 
			   id='employeeNumber' value=".$employeeNumber."></td>";
		echo "<td><input type='hidden' name='time".$i."' 
			   id='time".$i."' value=".$time."></td>";
		echo "<td><input type='hidden' name='totalRows' id ='totalRows' value='".$totalRows."'/></td>";
		echo "<td><input type='hidden' name='leaveNum".$i."' id='leaveNum".$i."' value=".$leaveNumber."></td>";
		echo "</tr>";
		}

		echo "</table></center><br/>
		<div style='padding-left: 10px'><input type='submit' name='submitEditLeave' id='submit' value='Save Changes'/></div></form>";
		
		if (!$errorFlag) {
			$_SESSION['valid'] = true;
			LeaveFormView :: requestEditLeave($employeeNumber);
		}					
		?>			
							<center>
								<p class="links"><a href='menu.php' class="more">&laquo;&laquo;&nbsp;&nbsp;Home&nbsp;&nbsp;&raquo;&raquo;</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='startAdd.php' class="more">&laquo;&laquo;&nbsp;&nbsp;Add Leave&nbsp;&nbsp;&raquo;&raquo;</a></p>							
							</center>
						</div>
					</div>
					</div>
				<!-- end content -->						
					<div style="clear: both;">&nbsp;</div>
				</div>
				</div>
				<!-- end page -->
			</div>
			<div id="footerEdit">
			</div>		
		</body></html>
<?php }else
		header("Location: menu.php"); ?>